package com.kaili.basic.scheduler;

import com.kaili.basic.service.IDeviceSignService;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * @Desc: 定时任务
 * @author: zhouyijian
 * @Time: 2019/8/8 13:57
 * @Copyright: © 2018 杭州凯立通信有限公司 版权所有
 * @Warning: 本内容仅限于公司内部传阅, 禁止外泄或用于其它商业目的
 */
public class TaskScheduler {

    @Autowired
    private IDeviceSignService deviceSignService;

    public  TaskScheduler(IDeviceSignService deviceSignService){
        this.deviceSignService =deviceSignService;
    }

    //创建线程池
    ScheduledExecutorService executor = Executors.newScheduledThreadPool(10);

    //开启任务
    public void start(){
        LoopSignTask task = new LoopSignTask(deviceSignService,executor);
        executor.scheduleAtFixedRate(task,1,15*60, TimeUnit.SECONDS);

    }

    //结束任务
    public void shutdown(){

        this.executor.shutdown();
    }

}


